
clear

use "$dir\data\cleaned\estimation_data_wide.dta", clear

rename cat_czone czone

tab state2016, gen(state1_)
drop state1_1

*need to reshape long
keep ch_sht_* state2016 czone czone_pop2016 

global stem ch_sht_contemp_mean_oas_std ch_sht_inst_mean_ind_std_2000  ch_sht_inst_mean_ind_std_1970 ///
ch_sht_epop100 ch_sht_lwg_annual_r  ch_sht_lwg_wage_pop_r ///
ch_sht_oas_pop_pct ch_sht_non_oas_pop_pct ch_sht_oas_college_pct ch_sht_non_oas_college_pct ///
ch_sht_oas_lwg_annual_r ch_sht_non_oas_lwg_annual_r ch_sht_oas_lwg_yr_col_r ///
ch_sht_non_oas_lwg_yr_col_r ch_sht_oas_lwg_yr_nocol_r ch_sht_non_oas_lwg_yr_nocol_r ///
ch_sht_oas_share ch_sht_non_oas_share ch_sht_flfp ch_sht_mlfp ch_sht_oas_nc_wage_gap ch_sht_oas_col_wage_gap

reshape long $stem, i(czone) 

tab czone, gen(cz_)
drop cz_1

gen second_period = _j==2
	
global x_endog ch_sht_contemp_mean_oas_std
global x_inst_2000 ch_sht_inst_mean_ind_std_2000
global x_inst_1970 ch_sht_inst_mean_ind_std_1970

gen  ch_sht_flfp100 =   ch_sht_flfp*100 
gen ch_sht_mlfp100 = ch_sht_mlfp*100



*ftest

ivregress 2sls  ch_sht_oas_share  cz_*  second_period ($x_endog   =  $x_inst_1970 )       [aweight=czone_pop2016], vce(r)
		estat firststage


	*first stage
			reghdfe $x_endog    $x_inst_1970    [aweight=czone_pop2016] ,  absorb(czone second_period) vce(robust)
		outreg2   using "$dir/output/Rob_longdif1970.xls", replace dec(3) excel alpha(0.001, 0.01, 0.05) symbol(***, **, *) drop(o.*)

	*2sls

	foreach var in 	oas_pop_pct oas_college_pct epop100 lwg_annual_r lwg_wage_pop_r oas_nc_wage_gap  oas_col_wage_gap {
	ivregress 2sls ch_sht_`var'  cz_* second_period ($x_endog   =  $x_inst_1970 )     [aweight=czone_pop2016],  vce(robust)
		outreg2   using "$dir/output/Rob_longdif1970.xls", append dec(3) excel alpha(0.001, 0.01, 0.05) symbol(***, **, *) drop(yr1_* cz_* o.*)
	}
	
	
	*2000 instrument
	*ftest
			ivregress 2sls  ch_sht_oas_share  cz_*  second_period ($x_endog   =  $x_inst_2000 )       [aweight=czone_pop2016], vce(r)
		estat firststage
		

	*first stage
	
reghdfe $x_endog    $x_inst_2000    [aweight=czone_pop2016] ,  absorb(czone second_period) vce(robust)
outreg2   using "$dir/output/Rob_longdif2000.xls", replace dec(3) excel alpha(0.001, 0.01, 0.05) symbol(***, **, *) drop(o.*)
			

	*2sls
	foreach var in 	oas_pop_pct oas_college_pct epop100 lwg_annual_r lwg_wage_pop_r oas_nc_wage_gap  oas_col_wage_gap {
	ivregress 2sls ch_sht_`var'  cz_* second_period ($x_endog   =  $x_inst_2000 )     [aweight=czone_pop2016], vce(robust)
		outreg2   using "$dir/output/Rob_longdif2000.xls", append dec(3) excel alpha(0.001, 0.01, 0.05) symbol(***, **, *) drop(yr1_* cz_* o.*)
	}
	



